package com.jtx.miaoah2.config;

import com.jtx.miaoah2.Cache.BlankUserCache;
import com.jtx.miaoah2.Cache.HotCache;
import com.jtx.miaoah2.Mapper.SkGoodsMapper;
import com.jtx.miaoah2.handler.HotKeyInterceptor;
import com.jtx.miaoah2.handler.UserTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 季台星
 * @Date 2023 07 23 14 54
 */
@Component
public class MvcConfig implements WebMvcConfigurer {
    private final BlankUserCache blankUserCache;
    private final HotCache hotCache;


    @Autowired
    public MvcConfig(BlankUserCache blankUserCache,HotCache hotCache) {
        this.blankUserCache = blankUserCache;
        this.hotCache = hotCache ;
    }



    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserTokenInterceptor(blankUserCache))
                .addPathPatterns("/**")
                .excludePathPatterns("/api/v1/login/**")
                .excludePathPatterns("/error")
                .excludePathPatterns("/api/v1/buy/panicBuy");
        registry.addInterceptor(new HotKeyInterceptor(hotCache))
                .addPathPatterns("/api/v1/goods/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
